package com.guojian.jdbc;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author GuoJian
 *
 */
public class JdbcTemplateFactory {

	private static final Map<String, JdbcTemplateX> templateMap = new ConcurrentHashMap<String, JdbcTemplateX>();

	public synchronized static JdbcTemplateX getJdbcTemplate(String dataSourceName, DBType dbType) {
		JdbcTemplateX template = templateMap.get(dataSourceName);
		if (template == null) {
			template = new JdbcTemplateX(DataSourceFactory.getDataSource(dataSourceName), dbType);
			templateMap.put(dataSourceName, template);
		}
		return template;
	}

	public static JdbcTemplateX getTestJdbcTemplate() {
		return getJdbcTemplate("test", DBType.oracle);
	}

	public static void main(String[] args) {
		JdbcTemplateX test = getTestJdbcTemplate();
		System.out.println(test);
		StringBuilder sb = new StringBuilder();
		sb.append(" insert into SYS_ROLE ( role_name, role_key, role_sort, data_scope, status, del_flag, create_by, create_time, ");
		sb.append(" update_by, update_time, remark) ");
		sb.append(" VALUES('test','test',10,1,0,0,'test',sysdate,'test',sysdate,?) ");
		Number id = test.insertWithReturnNumberKey(sb.toString(), new String[] { "ROLE_ID" }, "测试");
		System.out.println(id);

	}

}
